package com.sqx.modules.health.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sqx.modules.health.common.Result;
import com.sqx.modules.health.entity.NcgService;
import com.sqx.modules.health.entity.ServicetypeByHealth;
import com.sqx.modules.health.service.INcgServiceService;
import com.sqx.modules.health.service.IServicetypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 服务项目类型表 前端控制器
 * </p>
 *
 * @author gxy
 * @since 2022-06-13
 */

@Api(value = "服务项目类型表", tags = "服务项目类型接口", description = "")
@RestController
@RequestMapping("/health/servicetype")
public class ServicetypeController {
    @Autowired
    private IServicetypeService servicetypeService;

    @Autowired
    private INcgServiceService ncgService;

    // 新增或更新
    @PostMapping("/save")
    @ApiOperation(value = "新增或更新服务项目类型表", notes = "新增或更新服务项目类型表")
    public Result save(@RequestBody ServicetypeByHealth servicetypeByHealth){
        return Result.success(servicetypeService.save(servicetypeByHealth));
    }

    // 根据ID删除
    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "根据ID删除服务项目类型表", notes = "根据ID删除服务项目类型表")
    public Result delete(@PathVariable Integer id){
        return Result.success(servicetypeService.removeById(id));
    }

    // 根据IDS删除
    @PostMapping("/del/batch")
    @ApiOperation(value = "根据IDS删除服务项目类型表", notes = "根据IDS删除服务项目类型表")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        return Result.success(servicetypeService.removeByIds(ids));
    }

    // 查询全部
    @GetMapping("/findAll")
    @ApiOperation(value = "查询全部服务项目类型表", notes = "查询全部服务项目类型表")
    public Result findAll(){
        return Result.success(servicetypeService.list());
    }

    // 根据ID查询一条记录
    @GetMapping("/findOne")
    @ApiOperation(value = "根据ID查询一条记录服务项目类型表", notes = "根据ID查询一条记录服务项目类型表")
    public Result findOne(@PathVariable Integer id){
        return Result.success(servicetypeService.getById(id));
    }

    // 分页查询
    @GetMapping("/findPage")
    @ApiOperation(value = "分页查询服务项目类型表", notes = "分页查询服务项目类型表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", paramType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "一页数据条数", paramType = "String"),
            @ApiImplicitParam(name = "hid", value = "医院id", paramType = "Long"),
//            @ApiImplicitParam(name = "isable", value = "是否启用 0：启用  1：禁用", paramType = "Integer"),
    })
    public Result findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize,
                           @RequestParam(required = false, defaultValue = "")Long hid){
        QueryWrapper<ServicetypeByHealth> queryWrapper = new QueryWrapper<>();
        if (hid != null) {
            queryWrapper.eq("hid", hid);
        }
        queryWrapper.orderByDesc("id");
        return  Result.success(servicetypeService.page(new Page<>(pageNum,pageSize),queryWrapper));
    }

    @GetMapping("/showServiceType")
    @ApiOperation(value = "小程序首页服务项目分类查询接口", notes = "小程序首页服务项目分类查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hid", value = "医院id", paramType = "Long"),
    })
    public Result showServiceType(@RequestParam(required = false, defaultValue = "")Long hid){
        QueryWrapper<ServicetypeByHealth> queryWrapper = new QueryWrapper<>();
        if (hid != null) {
            queryWrapper.eq("hid", hid);
        }
        queryWrapper.eq("isable", 0); // 小程序首页展示所有启用的项
        queryWrapper.orderByAsc("id");
        return  Result.success(servicetypeService.list(queryWrapper));
    }

    @GetMapping("/findService")
    @ApiOperation(value = "小程序端根据点击的项目分类查询对应的服务项目", notes = "小程序端根据点击的项目分类查询对应的服务项目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hid", value = "医院id", paramType = "Long"),
            @ApiImplicitParam(name = "typeid", value = "服务项目id", paramType = "Long"),
    })
    public Result findService(@RequestParam(required = false, defaultValue = "")Long hid,
                              @RequestParam(required = false, defaultValue = "") Integer typeid){
        QueryWrapper<NcgService> queryWrapper = new QueryWrapper<>();
        if (hid != null) {
            queryWrapper.eq("hid", hid);
        }
        if (typeid != null) {
            queryWrapper.eq("typeid", typeid);
        }
        queryWrapper.eq("isable", 0); // 小程序首页展示所有启用的项
        queryWrapper.orderByAsc("id");
        return  Result.success(ncgService.list(queryWrapper));
    }

}

